var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
			hide:true
		}, {
			colkey : "cateName",
			name : "申请事项",
			renderData : function(rowindex,data, rowdata, column) {
				if(data == ""){
					return rowdata.title;
				}else{
					return data;
				}
			}
		},  {
			colkey : "createUser",
			name : "办事人"
		}, {
			colkey : "details",
			name : "详情"
		},{
			colkey : "star",
			name : "评分",
			renderData : function(rowindex,data, rowdata, column) {
				if(data)
					return data + "分";
				else
					return "";
			}
		},
		{
			colkey : "comment",
			name : "评论内容"
		},{
			colkey : "status",
			name : "状态",
			width : '90px',
			renderData : function(rowindex,data, rowdata, column) {
				if(data == "Y"){
					return "<label class='label-primary' style='color: #fff;padding: 3px 4px;border-radius: 3px;'>已办理</label>";
				}else {
					return "<label class='label-grey' style='color: #fff;padding: 3px 4px;border-radius: 3px;'>未办理</label>"
				}
			}
		}],
		jsonUrl : rootPath + '/matter/findByPage.shtml',
		checkbox : true,
		serNumber : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addMatter").click("click", function() {
		addMatter();
	});
	$("#delMatter").click("click", function() {
		delMatter();
	});
	$("#handle").click("click", function() {
		handleApply();
	});
	$("#qrcode").click("click", function() {
		qrcode();
	});
});

function handleApply() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择办理项！！");
		return;
	}

	layer.confirm('是否确认办理？', function(index) {
		var url = rootPath + '/matter/handle.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('办理成功');
			grid.loadData();
		} else {
			layer.msg('办理失败');
		}
	});
}

function addMatter() {
	var url =rootPath + '/matter/addUI.shtml';
	pageii = layer.open({
		title : "新增",
		type : 1,
		area : [ "900px", "80%" ],
		content : CommnUtil.ajax(url)
	});
}
function delMatter() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/matter/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}

function qrcode() {

	var url = rootPath + '/matter/codeUI.shtml';
	pageii = layer.open({
		title : "我的二维码",
		type : 1,
		area : [ "500px", "80%" ],
		content : CommnUtil.ajax(url)
	});

}